package com.tally.common.enums;

import com.tally.common.thread.IdWorker;
import com.tally.common.utils.DateUtils;
import com.tally.project.system.category.domain.Category;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.apache.commons.compress.utils.Lists;

import java.util.Date;
import java.util.List;

/**
 * @Author soul
 * @Date 2023/5/18 19:31
 * @Description 日常账单分类
 */
@AllArgsConstructor
@NoArgsConstructor
public enum EverydayCategoryEnums {
    /** 收入 */
    INCOME_1("工资", BillingClassifyEnums.INCOME.getValue(), "red-packet"),
    INCOME_2("奖金", BillingClassifyEnums.INCOME.getValue(), "red-packet"),

    /** 支出 */
    OUTLAY_1("餐饮日常", BillingClassifyEnums.OUTLAY.getValue(), "red-packet"),
    OUTLAY_2("居家日常", BillingClassifyEnums.OUTLAY.getValue(), "red-packet"),
    OUTLAY_3("购物消费", BillingClassifyEnums.OUTLAY.getValue(), "red-packet"),

    ;
    /** 名称 */
    private String name;
    /** 类型 */
    private int type;
    /** 图标 */
    private String icon;

    public static List<Category> toList(long userId, long bookId) {
        // 当前时间
        Date nowDate = DateUtils.getNowDate();
        // 分布式自增长ID
        IdWorker idWorker = new IdWorker();
        // Lists.newArrayList()其实和new ArrayList()几乎一模
        List list = Lists.newArrayList();
        //  一样, 唯一它帮你做的(其实是javac帮你做的), 就是自动推导(不是"倒")尖括号里的数据类型.
        for (EverydayCategoryEnums obj : EverydayCategoryEnums.values()) {
            Category category = new Category(idWorker.nextId(), userId, bookId, obj.name, obj.type, obj.icon);
            category.setCreateTime(nowDate);
            category.setUpdateTime(nowDate);
            list.add(category);
        }
        return list;
    }
}
